package com.coderside.fragment.Reference;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;

import com.coderside.fragment.json.Dog;
import com.coderside.fragment.json.Persons;
import com.coderside.fragment.json.Dogs;
import com.coderside.fragment.json.Person;

public class Test {

	public static void main(String[] args) {
		//构造一个Persons对象
		Persons persons = new Persons();
		persons.setId("1");
		Person p = new Person();
		p.setDateAttr(new Date());
		p.setName("dog");
		List<Person> list = new ArrayList<Person>();
		list.add(p);
		persons.setData(list);
		//构造一个Dogs对象
		Dogs dogs = new Dogs();
		try {
			BeanUtils.copyProperties(dogs, persons);
			for (int i = 0; i < dogs.getData().size(); i++) {
				//打印出来的是一个人com.coderside.fragment.json.Person对象
				System.out.println(dogs.getData().get(i));
				//				下面这句看起来是正常的 运行就会抛异常
				//				Dog dog = dogs.getData().get(i);
			}
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
	}
}
